package com.oocl.o2o.admin.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.log4j.Logger;




public class ImageUtil {
	//"/config.properties"
	
	private final static String PATH=ConfigBaseUtil.getPropertiesInfo("path");
	private final static String IMAGETYPE=ConfigBaseUtil.getPropertiesInfo("imageType");
	
	
	
	
	
	private static Logger logger = Logger.getLogger(ImageUtil.class);
	
		public static void showImage(String imagePath,OutputStream outputStream){
			//C:\\Users\\wuca3\\Desktop\\1.jpg
			try {
				InputStream  imInputStream=new FileInputStream(imagePath);
				byte[]buf=new byte[128];
				int len=0;
				while ((len=imInputStream.read(buf))!=-1) {
					outputStream.write(buf, 0, len);
					
				}
				outputStream.close();
				imInputStream.close();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				logger.error("FileNotFoundException--"+e.getMessage());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				logger.error("IOException--"+e.getMessage());
			}
		}
		
		/**
		 * 
		 * @param uname
		 * @param type
		 * @return
		 */
		public static String getImagePath(String uname,String type){
			String filePath=null;
			if ("id".equals(type)) {
				
				filePath= PATH+"/"+ConfigBaseUtil.getPropertiesInfo("idCardSrc")+"/"+uname+"."+IMAGETYPE;
			}
			if ("po".equals(type)) {
				filePath= PATH+"/"+ConfigBaseUtil.getPropertiesInfo("portraitSrc")+"/"+uname+"."+IMAGETYPE;
			}
			if ("advert".equals(type)) {
				filePath= PATH+"/"+ConfigBaseUtil.getPropertiesInfo("advert")+"/"+uname+"."+IMAGETYPE;
			}
			return filePath;
		}
	
	
	
}
